<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

Class LoginBox extends CWidget {

    public $httpReferer = '';

    public function run() {
	$modelForm = new LoginForm;
	if (isset($_POST['ajax']) && $_POST['ajax'] === "login-form") {
//	    $modelForm->attributes = $_POST['LoginForm'];
	    echo CActiveForm::validate($modelForm);
	    Yii::app()->end();
	}

	if (isset($_POST['LoginForm'])) {
	    $modelForm->attributes = $_POST['LoginForm'];
	    if ($modelForm->validate() && $modelForm->login()) {
//		Yii::app()->controller->redirect(Yii::app()->user->returnUrl);
		Yii::app()->controller->redirect(SITE_NAME_URL . 'dashboard');
	    } else {
		$modelForm->email = '';
		$modelForm->password = '';
	    }
	}

	$this->render('login-box', array('modelForm' => $modelForm));
    }

}

